package com.xauto.pioneer.appuser.activity.mine.user;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.xauto.pioneer.appuser.MyApplication;
import com.xauto.pioneer.appuser.R;
import com.xauto.pioneer.appuser.activity.BaseActivity;
import com.xauto.pioneer.appuser.http.BaseLHttpHandler;
import com.xauto.pioneer.appuser.http.LHttpLib;
import com.xauto.pioneer.appuser.model.CarOrderOtherDetailInfo;
import com.xauto.pioneer.appuser.model.JSONStatus;
import com.xauto.pioneer.appuser.view.TopBar;

import butterknife.Bind;

/**
 * Created by Ellis.Li on 2017/5/25.
 */

public class OrderOtherDetailActivity extends BaseActivity {
    @Bind(R.id.topBar)
    TopBar topBar;
    String additional_order_id = "";
    CarOrderOtherDetailInfo CarOrderOtherDetailInfo;
    @Bind(R.id.tvOrderNo)
    TextView tvOrderNo;
    @Bind(R.id.tvCarPlate)
    TextView tvCarPlate;
    /**问题类别*/
    @Bind(R.id.other_tvRefuelName)
    TextView tvRefuelName;
    /**费用*/
    @Bind(R.id.other_tvRefuelDate)
    TextView tvRefuelDate;
    /**状态*/
    @Bind(R.id.other_tvRefuelStatus)
    TextView tvRefuelStatus;
    /**文字描述*/
    @Bind(R.id.car_refuel_comment)
    TextView car_refuel_comment;
    /**照片*/
    @Bind(R.id.refuel_one_image)
    ImageView refuel_one_image;
    @Bind(R.id.refuel_two_image)
    ImageView refuel_two_image;
    @Bind(R.id.refuel_three_image)
    ImageView refuel_three_image;
    @Bind(R.id.refuel_four_image)
    ImageView refuel_four_image;
    @Bind(R.id.refuel_five_image)
    ImageView refuel_five_image;
    private DisplayImageOptions options;
    public static void startAction(Context context, String additional_order_id) {
        Intent intent = new Intent(context, OrderOtherDetailActivity.class);
        intent.putExtra("additional_order_id", additional_order_id);
        context.startActivity(intent);
    }

    @Override
    protected int getContentView() {
        return R.layout.ac_orderother_detail;
    }

    @Override
    protected void initView() {
        topBar.showView(TopBar.LEFT_IMAGE_BTN, TopBar.TITLE);
        topBar.setImage(TopBar.LEFT_IMAGE_BTN, R.mipmap.ic_common_left);
        topBar.setText(TopBar.TITLE, "附加费用详情");
        topBar.setLeftOnClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    @Override
    protected void initData() {
        options = MyApplication.getDisplayImageOptions(mContext, 40, R.mipmap.ic_default_user_avatar);
        additional_order_id = getIntent().getStringExtra("additional_order_id");
    }

    @Override
    protected void onStart() {
        super.onStart();
        loadRefuelDetail();
    }

    /**
     * 加载详情信息
     */
    private void loadRefuelDetail() {
        new LHttpLib().getCarOrderOtherDetail(mContext, memberId, additional_order_id, new BaseLHttpHandler(mContext, true, true) {
            @Override
            public void onSuccess(JSONStatus jsonStatus) {
                super.onSuccess(jsonStatus);
                CarOrderOtherDetailInfo = new CarOrderOtherDetailInfo().parse(jsonStatus.data.optJSONObject("car_additional_info"));
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        showRefuelData();
                    }
                });
            }
        });
    }

    /**
     * 显示相关数据
     */
    private void showRefuelData() {
        tvOrderNo.setText(CarOrderOtherDetailInfo.car_order_no);
        tvCarPlate.setText(CarOrderOtherDetailInfo.plate_no);
        tvRefuelName.setText(CarOrderOtherDetailInfo.additional_order_category_name);
        //todo 缺少加油日子
        tvRefuelDate.setText(CarOrderOtherDetailInfo.additional_amount_foramt);
        tvRefuelStatus.setText(CarOrderOtherDetailInfo.additional_order_status_description);
        car_refuel_comment.setText(CarOrderOtherDetailInfo.additional_order_status_comment);
        switch (CarOrderOtherDetailInfo.additional_order_status_style_color){
            case "0":
                tvRefuelStatus.setTextColor(getResources().getColor(R.color.black));
                break;
            case "1":
                tvRefuelStatus.setTextColor(getResources().getColor(R.color.red));
                break;
            case "2":
                tvRefuelStatus.setTextColor(getResources().getColor(R.color.grey));
                break;
        }
        if (CarOrderOtherDetailInfo.Other_image_list != null){
            int size = CarOrderOtherDetailInfo.Other_image_list.size();
            switch (size){
                case 1:
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(0),refuel_one_image,options);
                    break;
                case 2:
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(0),refuel_one_image,options);
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(1),refuel_two_image,options);
                    break;
                case 3:
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(0),refuel_one_image,options);
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(1),refuel_two_image,options);
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(2),refuel_three_image,options);
                    break;
                case 4:
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(0),refuel_one_image,options);
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(1),refuel_two_image,options);
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(2),refuel_three_image,options);
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(3),refuel_four_image,options);
                    break;
                case 5:
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(0),refuel_one_image,options);
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(1),refuel_two_image,options);
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(2),refuel_three_image,options);
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(3),refuel_four_image,options);
                    imageLoader.displayImage(CarOrderOtherDetailInfo.Other_image_list.get(4),refuel_five_image,options);
                    break;
            }
        }
    }
}
